/***************************************************************************************
 The copyright in this software is being made available under the BSD License, included
 below. This software may be subject to other third party rights,including patent rights,
 and no such rights are granted under this license.

 Regents of the Tsinghua University, Peking University, Zhejiang University, HKUST
 Tsinghua University, Peking University, Zhejiang University, HKUST 2011

 Copyright (c) 2011, Regents of the Tsinghua University, Peking University, Zhejiang
 University, HKUST. All Rights Reserved.

 Redistribution and use in source and binary forms, with or without modification, are
 permitted provided that the following conditions are met:
   * Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
   * Neither the names of the copyright holders nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 OF SUCH DAMAGE.
***************************************************************************************/

/*!
***************************************************************************
* \file
*    rdoq.h
*
* \brief
*    Headerfile for RDO_Q
*
* \author
*    Xingguo Zhu     2009-12-28      < 05xxgcsgx@zju.edu.cn >
***************************************************************************
*/

#ifndef _RDOQ_H_
#define _RDOQ_H_

#include"defines.h"

#ifdef RDO_Q


typedef struct level_data_struct
{
    int level[3];
    int  levelDouble;
    double  errLevel[3];
    int noLevels;
    int coeff_ctr;
    int pre_level;
    int sign; //added by ckj
    double  pre_err;
} levelDataStruct;

void RDO_Q_init8x8( int curr_blk[8][8], int qp, int intra_flag, int block8x8, levelDataStruct levelData[] );
void RDO_Quant8x8( levelDataStruct *levelData, int *levelTrellis,int block8x8, int intra_flag, double lambda );
double EstBits8x8( int block8x8, int intra_flag );

void RDO_Q_init16x16( int curr_blk[16][16], int qp, int intra_flag, levelDataStruct levelData[] ) ;
void RDO_Quant16x16( levelDataStruct levelData[256], int levelTrellis[256], int intra_flag, double lambda );
int  EstBits16x16( int intra_flag );

void RDO_Q_init4x4( int curr_blk[4][4], int qp, int intra_flag, int block8x8, int block4x4, levelDataStruct levelData[] ) ;
void RDO_Quant4x4( levelDataStruct *levelData, int levelTrellis[], int block8x8, int block4x4, int intra_flag, double lambda );
int EstBits4x4( int block8x8, int block4x4, int intra_flag ) ;

#endif

#endif
